{% load static %}
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <!-- logo开始 -->
            <a class="navbar-brand" href="{% url 'index:index' %}">AI Peng</a>
            <!-- logo结束 -->
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <!-- 左侧链接列表开始 -->
            <ul class="nav navbar-nav">
                <li><a href="{% url 'index:index' %}">首页</a></li>
                <li><a href="#">博客</a></li>
                <li><a href="#">视频</a></li>
                <li><a href="#">下载</a></li>
                <li><a href="#">关于</a></li>
                <li><a href="#">联系</a></li>
            </ul>
            <!-- 左侧链接列表结束 -->

            <!-- 顶部搜索开始 -->
            <form class="navbar-form navbar-left" method="get" action="/apps/index/search">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="请输入要搜索的内容" name="search">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
            <!-- 顶部搜索结束 -->

            <ul class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">
                        作者专区
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="{% url 'article:add' %}">添加文章</a></li>
                        <li><a href="#">我的博客</a></li>
                    </ul>
                </li>
                <li class="dropdown" id="user-center">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">
                        <span id="username_span">我的</span>
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="#">个人中心</a></li>
                        <li><a href="#">修改密码</a></li>
                        <li><a href="#">收藏</a></li>
                        <li><a href="#">评论</a></li>
                        <li><a href="#">消息</a></li>
                        <li><a href="{% url 'user:login_out' %}">注销</a></li>
                    </ul>
                </li>
                <li id="register_nav"><a href="{% url 'user:register' %}">注册</a></li>
                <li id="login_nav"><a href="{% url 'user:login' %}">登录</a></li>
            </ul>
        </div>
    </div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script src="{% static 'js/common.js' %}"></script>
<script>
    // 获取cookie
    let username = getCookie('username')
    if (username !== '') {
        $("#username_span").text(username)
        // 隐藏注册和登录
        $("#register_nav").css('display', 'none')
        $("#login_nav").css('display', 'none')
    } else {
        // 隐藏个人中心
        $("#user-center").css('display', 'none')
        // 显示注册和登录
        $("#register_nav").css('display', 'block')
        $("#login_nav").css('display', 'block')
    }
</script>